#!/bin/bash

source "/etc/profile"
JAR_FILE="admin-1.0.0.jar"
APP_NAME="admin.qbasic.hyzx.com"
LOG_DIR="/qbasic-data/log/${APP_NAME}"
TMP_FILE_DIR="/qbasic-data/tmp"
GCLOGPATH="${LOG_DIR}/gc.log"
JAVA_OPTS=" -server \
            -Xms2048m -Xmx2048m \
            -XX:MaxMetaspaceSize=256m \
            -Xmn750M \
            -XX:+UseConcMarkSweepGC -XX:+CMSParallelRemarkEnabled \
            -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=75 \
            -XX:+ScavengeBeforeFullGC -XX:+CMSScavengeBeforeRemark \
            -XX:+PrintGCDateStamps -verbose:gc -XX:+PrintGCDetails -Xloggc:${GCLOGPATH} \
            -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M \
            -Dsun.net.inetaddr.ttl=60 \
            -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${LOG_DIR}/heapdump.hprof"

#############intial work##########################
mkdir -p ${LOG_DIR}
mkdir -p ${TMP_FILE_DIR}
##############launch the service##################
nohup java ${JAVA_OPTS} -jar ${JAR_FILE} >> ${GCLOGPATH} 2>&1 &

##############check the service####################
ps aux | grep ${JAR_FILE} | grep -v grep > /dev/null 2>&1
if [ $? -eq 0 ]; then
    exit 0
else
    exit 1
fi
